package site.beanyon.now.aspect.log;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 定时任务日志切面
 */
@Aspect
@Component
class ScheduleServiceLogAspect {
    private Logger logger = LoggerFactory.getLogger(ScheduleServiceLogAspect.class);

    /**
     * 根据时间计划，定时创建时间卡片环绕通知
     *
     * @param jp 连接点
     */
    @Around("execution(* site.beanyon.now.service.ScheduleService.createDefaultTimePlanEveryDay(..))")
    private void createDefaultTimePlanEveryDay(ProceedingJoinPoint jp) throws Throwable {
        try {
            // 定时根据时间计划创建时间卡片
            jp.proceed();
        } catch (Throwable throwable) {
            // 创建异常
            logger.error("[error] schedule create time card");
            throw throwable;
        }

        // 创建后
        logger.info("[success] schedule create time card");
    }
}
